//
//  MemberTableViewCell.m
//  YouinRTCDemo
//
//  Created by super on 2021/10/31.
//

#import "MemberTableViewCell.h"

@implementation MemberTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self){
        [self initUI];
    }
    return self;
}

-(void)initUI{
    self.avatar = [UIImageView new];
    self.avatar.layer.cornerRadius = 15;
    self.avatar.layer.masksToBounds = YES;
    [self.contentView addSubview:self.avatar];
    
    self.nameLabel = [UILabel new];
    self.nameLabel.font = [UIFont systemFontOfSize:14];
    [self.contentView addSubview:self.nameLabel];
    
    self.infoLabel = [UILabel new];
    self.infoLabel.font = [UIFont systemFontOfSize:12];
    self.infoLabel.numberOfLines = 0;
    self.infoLabel.textColor = [UIColor grayColor];
    [self.contentView addSubview:self.infoLabel];
}

-(void)layoutSubviews{
    [super layoutSubviews];
    
    [self.avatar mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(16);
        make.width.height.mas_equalTo(30);
        make.top.equalTo(self.contentView).offset(5);
    }];
    
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.avatar.mas_right).offset(8);
        make.right.mas_equalTo(self.contentView).offset(-16);
        make.top.mas_equalTo(self.avatar);
        
    }];
    
    [self.infoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.avatar.mas_right).offset(8);
        make.right.mas_equalTo(self.contentView).offset(-16);
        make.top.mas_equalTo(self.nameLabel.mas_bottom).offset(4);
        make.bottom.mas_equalTo(self.contentView);
    }];
}

- (void)setInfo:(userInfoModel *)info{
    [self.avatar sd_setImageWithURL:[NSURL URLWithString:info.avatar]];
    self.nameLabel.text = info.userName;
    NSString *mic = info.is_mic_mute ? @"麦克风：关闭": @"麦克风：开启";
    NSString *camera = info.is_camera_mute ? @"摄像头：关闭": @"摄像头 ：开启";
    NSString *publish = info.interactive ? @"已上麦": @"未上麦";
    self.infoLabel.text = [NSString stringWithFormat:@"%@，%@，%@",mic,camera,publish];
}

@end
